package com.yanqu.road.server.manager.activity.shuihuyezipai;

import com.yanqu.road.entity.activity.shuihuyezipai.ShuiHuYeZiCardRoomData;
import com.yanqu.road.entity.activity.shuihuyezipai.ShuiHuYeZiCardUserBattleInfo;
import com.yanqu.road.entity.activity.shuihuyezipai.ShuiHuYeZiCardUserCard;
import com.yanqu.road.entity.activity.shuihuyezipai.ShuiYeZiCardJoinPvpUserInfo;
import com.yanqu.road.entity.activity.shuihuyezipai.config.ShuiHuYeZiCardActivityConfig;
import com.yanqu.road.entity.log.LogShuiHuYeZiCardPVPMatchRecord;
import com.yanqu.road.entity.player.CrossUserBaseInfo;
import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.logic.pb.PlayerBasePb;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.pb.activity.ShuiHuYeZiCardProto;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.server.manger.ShuiHuYeZiCardCommonMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @Description 水浒椰子派 pvp战斗
 * @Author cwq
 * @Data 2021/11/30 18:38
 */
public class ShuiHuYeZiCardActivityBattleMgr extends TempMgr {

    private static Logger logger = LogManager.getLogger(ShuiHuYeZiCardActivityBattleMgr.class.getName());

    /**
     * 上次打印匹配信息的时间
     */
    private static int lastPrintMatchInfoTime;

    /**
     * 上次打印房间数量的时间 ms
     */
    private static long lastPrintRoomInfoTime;

    /**
     * 最近50场的比赛时间  (计算时间用)
     */
    public static LinkedList<Integer> recentWaitTimeList = new LinkedList<>();

    public static int totalWaitTime = 0;

    /**
     * 最近50个参赛玩家  (匹配过程中 等待滚动用)
     */
    public static List<ShuiYeZiCardJoinPvpUserInfo> recentJoinerList = new ArrayList<>();

    /**
     * 所有等待匹配的玩家
     */
    public static Map<Long,ShuiHuYeZiCardUserBattleInfo> waitingPlayerMap = new ConcurrentHashMap<>();

    /**
     * 战斗房间 k:userId,v:房间
     */
    public static Map<Long, ShuiHuYeZiCardPVPRoom> pvpRoomMap = new ConcurrentHashMap<>();


    public static Object lock = new Object();

    /**
     * 战斗房间
     */
    public static List<ShuiHuYeZiCardPVPRoom> pvpRoomList = new CopyOnWriteArrayList<>();

    public static Random random = new Random();

    /**
     * 获取预匹配 信息
     */
    public static ShuiHuYeZiCardProto.ShuiHuYeZiCardGetPVPPreMatchInfoRespMsg.Builder getPreMatchInfo(int activityId,long userId) {
        ShuiHuYeZiCardProto.ShuiHuYeZiCardGetPVPPreMatchInfoRespMsg.Builder builder = ShuiHuYeZiCardProto.ShuiHuYeZiCardGetPVPPreMatchInfoRespMsg.newBuilder();
        int waitTime = 0;
        synchronized (recentWaitTimeList){
            if(recentWaitTimeList.size() > 0){
                // 实际匹配时间 + 预匹配时间
                ShuiHuYeZiCardActivityConfig activityConfig = ShuiHuYeZiCardActivityConfigMgr.getActivityConfig(activityId);
                int preMatchTime = activityConfig != null ? activityConfig.matchParamList.get(0) : 0;
                waitTime = totalWaitTime / recentWaitTimeList.size() + preMatchTime;
            }else {
                waitTime = ShuiHuYeZiCardActivityConfigMgr.getWaitTimeDefaultValue();
            }
        }
        List<ShuiYeZiCardJoinPvpUserInfo> list = null;
        synchronized (recentJoinerList){
            list = new ArrayList<>(recentJoinerList);
        }
        Collections.shuffle(list);
        int num = 10;
        List<Long> showUserInfoList = new ArrayList<>();
        for (ShuiYeZiCardJoinPvpUserInfo joinPvpUserInfo : list){
            if(num <= 0){
                break;
            }
            if(!ShuiHuYeZiCardActivityConfigMgr.getOpenActivityInfoMap().containsKey(joinPvpUserInfo.getActivityId())){
                continue;
            }
            if(joinPvpUserInfo.getUserId() != userId ){
                showUserInfoList.add(joinPvpUserInfo.getUserId());
                UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(joinPvpUserInfo.getUserId());
                if(userBaseInfo != null){
                    builder.addShowPlayList(ShuiHuYeZiCardProto.ShuiHuYeZiCardGetPVPPreMatchInfo.newBuilder()
                            .setRankScore(joinPvpUserInfo.getRankScore()).setShowPlayList(PlayerBasePb.parsePlayerBaseTempMsg(userBaseInfo)));
                    num--;
                }
            }
        }
        // 如果未满 就随机下发玩家
        if(num > 0){
            for (CrossUserBaseInfo item : CrossUserMgr.getCrossUserBaseInfoList()){
                if(num <= 0){
                    break;
                }
                if(item.getUserId() != userId && !showUserInfoList.contains(item.getUserId()) && !StringUtils.isNullOrEmpty(item.getUserBaseInfo().getNickName())){
                    builder.addShowPlayList(ShuiHuYeZiCardProto.ShuiHuYeZiCardGetPVPPreMatchInfo.newBuilder().setRankScore(0).setShowPlayList(PlayerBasePb.parsePlayerBaseTempMsg(item.getUserBaseInfo())));
                    num--;
                }
            }
        }

        builder.setWaitTime(waitTime);
        builder.setRet(0);
        return builder;
    }

    /**
     * 开始匹配
     */
    public static void startMatch(int activityId,long serverId,long userId,int rankScore,int roomType,Map<Integer, ShuiHuYeZiCardUserCard> cardMap){
        ShuiHuYeZiCardProto.ShuiHuYeZiGetCardStartGameToServerMsg.Builder crossMsg = ShuiHuYeZiCardProto.ShuiHuYeZiGetCardStartGameToServerMsg.newBuilder();
        crossMsg.setRoomType(roomType);
        ShuiHuYeZiCardProto.ShuiHuYeZiGetCardStartGameRespMsg.Builder stcMsg = ShuiHuYeZiCardProto.ShuiHuYeZiGetCardStartGameRespMsg.newBuilder();
        ShuiHuYeZiCardActivityConfig activityConfig = ShuiHuYeZiCardActivityConfigMgr.getActivityConfig(activityId);
        // 判断是否在匹配 期间
        if(!ShuiHuYeZiCardCommonMgr.inMatchTime(activityConfig)){
            stcMsg.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_NO_IN_MATCH_TIME);
            crossMsg.setStcMsg(stcMsg);
            MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_START_GAME_FROM_CROSS,crossMsg));
            return;
        }
        synchronized (lock){
            if(waitingPlayerMap.containsKey(userId)){
                // 不能重复匹配
                stcMsg.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_DUPLICATE_MATCH);
                crossMsg.setStcMsg(stcMsg);
                MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_START_GAME_FROM_CROSS,crossMsg));
                return;
            }

            if(pvpRoomMap.containsKey(userId)){
                stcMsg.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_IN_GAME);
                crossMsg.setStcMsg(stcMsg);
                MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_START_GAME_FROM_CROSS,crossMsg));
                return;
            }

            ShuiHuYeZiCardUserBattleInfo userBattleInfo = new ShuiHuYeZiCardUserBattleInfo();
            userBattleInfo.setUserId(userId);
            userBattleInfo.setActivityId(activityId);
            userBattleInfo.setRankScore(rankScore);
            userBattleInfo.setRoomType(roomType);
            userBattleInfo.setServerId(serverId);
            userBattleInfo.setMatchTime(DateHelper.getCurrentSecond());
            userBattleInfo.setUserCardMap(cardMap);
            waitingPlayerMap.put(userId,userBattleInfo);

            stcMsg.setRet(0);
            crossMsg.setStcMsg(stcMsg);
            // 为了保证 匹配成功的协议优先 到达服务器
            MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_START_GAME_FROM_CROSS,crossMsg));
        }
    }


    /**
     * 取消匹配  注意 取消的时候正好匹配到
     * @param userId
     * @return
     */
    public static ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchGameToServerMsg.Builder cancelMatch(long userId){
        ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchGameToServerMsg.Builder crossMsg = ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchGameToServerMsg.newBuilder();
        ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchRespMsg.Builder stcMsg = ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchRespMsg.newBuilder();
        synchronized (lock){
            if(pvpRoomMap.containsKey(userId)){
                // 说明已经匹配成功了
                stcMsg.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_IN_GAME_NO_CANCEL_MATCH);
                crossMsg.setStcMsg(stcMsg);
                return crossMsg;
            }
            ShuiHuYeZiCardUserBattleInfo battleInfo = waitingPlayerMap.remove(userId);
            if(battleInfo != null){
                crossMsg.setRoomType(battleInfo.getRoomType());
            }
        }
        stcMsg.setRet(0);
        crossMsg.setStcMsg(stcMsg);
        return crossMsg;
    }


    /**
     * 发送消息
     * @param userId
     * @return
     */
    public static ShuiHuYeZiCardProto.ShuiHuYeZiCardSendMessageRespMsg.Builder sendMsg(long userId,int expressId){
        ShuiHuYeZiCardProto.ShuiHuYeZiCardSendMessageRespMsg.Builder builder = ShuiHuYeZiCardProto.ShuiHuYeZiCardSendMessageRespMsg.newBuilder();
        ShuiHuYeZiCardPVPRoom pvpRoom = pvpRoomMap.get(userId);
        if(pvpRoom == null){
            builder.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_NOT_OPEN_GAME);
            return builder;
        }
        int ret = pvpRoom.sendMsg(userId,expressId);
        if(ret == 0){
            builder.setSendTime(DateHelper.getCurrentSecond());
        }
        builder.setRet(ret);
        return builder;
    }

    /**
     * 出牌
     * @param userId
     * @param id
     * @param round
     * @return
     */
    public static void playCard(long userId,long serverId, int id, int round){
        ShuiHuYeZiCardPVPRoom pvpRoom = pvpRoomMap.get(userId);
        if(pvpRoom == null){
            ShuiHuYeZiCardProto.ShuiHuYeZiCardPlayCardRespMsg.Builder builder = ShuiHuYeZiCardProto.ShuiHuYeZiCardPlayCardRespMsg.newBuilder();
            builder.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_NOT_OPEN_GAME);
            MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(ClientProtocol.U_SHUIHUYEZICARD_PLAY_CARD,builder));
            return;
        }
        pvpRoom.playCard(userId,serverId,id,round);
    }

    /**
     * 自动出牌
     */
    public static synchronized void autoPlayCard(){
        if(pvpRoomList.size() <= 0){
            return;
        }
        long now = DateHelper.getCurrentTime();
        for (ShuiHuYeZiCardPVPRoom item : pvpRoomList){
            if(now < item.getRoundEndTime()){
                continue;
            }
            item.autoPlayCard();
        }
        if(now - lastPrintRoomInfoTime >= DateHelper.MINUTE_MILLIONS){
            // 一分钟打印一次
            lastPrintRoomInfoTime = now;
            logger.info("水浒叶子牌，当前正在开启的房间数量为：{}",pvpRoomList.size());
        }

    }

    /**
     * 匹配
     */
    public static void match(){
        // 人数不足n个不匹配
        if(waitingPlayerMap.size() <= 0){
            return;
        }
        synchronized (lock){
            int waitingPlayerNum = waitingPlayerMap.size();
            Iterator<ShuiHuYeZiCardUserBattleInfo> iterable = waitingPlayerMap.values().iterator();
            // 被匹配到的玩家
            List<ShuiHuYeZiCardUserBattleInfo> matchedUserList = new ArrayList<>();
            int now = DateHelper.getCurrentSecond();
            while (iterable.hasNext()){
                ShuiHuYeZiCardUserBattleInfo item = iterable.next();
                ShuiHuYeZiCardActivityConfig activityConfig = ShuiHuYeZiCardActivityConfigMgr.getActivityConfig(item.getActivityId());
                long waitTime = now - item.getMatchTime();
                if(!ShuiHuYeZiCardCommonMgr.inMatchTime(activityConfig) || waitTime >= (activityConfig.matchParamList.get(2) - activityConfig.matchParamList.get(0))){
                    // 匹配时间到了 取消匹配
                    iterable.remove();
                    overTimeMatch(item);
                    // 加日志
                    ShuiHuYeZiCardActivityLogMgr.addLogShuiHuYeZiCardPVPMatchRecord(new LogShuiHuYeZiCardPVPMatchRecord(item.getActivityId(),item.getUserId(),item.getRankScore(),0,0,item.getMatchTime(),now));
                    continue;
                }
                if(waitingPlayerMap.size() < activityConfig.SHUIHUYEZICARD_MIN_MATCH_NUM){
                    // 小于匹配人数
                    continue;
                }
                if(matchedUserList.contains(item)){
                    // 已经被匹配到
                    continue;
                }

                ShuiHuYeZiCardUserBattleInfo target = null;
                // 允许的段位差
                long diffLevel = waitTime / activityConfig.matchParamList.get(1);
                for (int i = 0; i <= diffLevel; i++) {
                    // 进入匹配超过15秒后，每增加15秒则扩大一次匹配的段位范围，直到可以匹配到玩家为止。（即原来处于段位5，范围扩大至4~6，再扩大变为3~7，在该范围段内，另一方均将该玩家视为同段位玩家）
                    target = findTarget(item,true,true,i,matchedUserList);
                    if(target != null) {
                        break;
                    }
                }
                if(target == null && waitTime >= activityConfig.SHUIHUYEZICARD_EXCEED_TIME_EXPAND_SCOPE - activityConfig.matchParamList.get(0)){
                    // 进入匹配超过45秒后，玩家可以匹配到同区服的玩家，玩家可以匹配到非相同模式的玩家
                    for (int j = 0; j <= diffLevel; j++) {
                        target = findTarget(item,false,false,j,matchedUserList);
                        if(target != null){
                            break;
                        }
                    }
                }
                if(target != null){
                    // 创建房间
                    boolean success = createRoom(item,target);
                    if (success){
                        // 加入匹配时间
                        List<ShuiHuYeZiCardUserBattleInfo> list = new ArrayList<>();
                        list.add(target);
                        list.add(item);
                        addWaitTime(waitTime,list);
                        // 加日志
                        ShuiHuYeZiCardActivityLogMgr.addLogShuiHuYeZiCardPVPMatchRecord(new LogShuiHuYeZiCardPVPMatchRecord(item.getActivityId(),item.getUserId(),item.getRankScore(),target.getUserId(),target.getRankScore(),item.getMatchTime(),now));
                        ShuiHuYeZiCardActivityLogMgr.addLogShuiHuYeZiCardPVPMatchRecord(new LogShuiHuYeZiCardPVPMatchRecord(target.getActivityId(),target.getUserId(),target.getRankScore(),item.getUserId(),item.getRankScore(),target.getMatchTime(),now));
                        logger.info("水浒叶子牌，创建房间成功。player1:{},player2：{},waitTime:{}",item.getUserId(),target.getUserId(),waitTime);
                    }
                    // 取消两个匹配到的玩家
                    iterable.remove();
                    matchedUserList.add(target);
                }
            }
            for (ShuiHuYeZiCardUserBattleInfo userBattleInfo : matchedUserList){
                waitingPlayerMap.remove(userBattleInfo.getUserId());
            }
            if(now - lastPrintMatchInfoTime >= 60){
                // 一分钟打一次
                lastPrintMatchInfoTime = now;
                logger.info("waitingPlayerNum : {},剩余 waitingPlayerNum：{}",waitingPlayerNum,waitingPlayerMap.size());
            }
        }
    }

    /**
     * 寻找目标
     * @param item  需要配置的玩家
     * @param isFilterSameServer 是否过滤同区服
     * @param isFilterDiffModel 是否过滤不同模式
     * @param diffLevel 允许的段位差值
     */
    public static ShuiHuYeZiCardUserBattleInfo findTarget(ShuiHuYeZiCardUserBattleInfo item,boolean isFilterSameServer,boolean isFilterDiffModel,int diffLevel,List<ShuiHuYeZiCardUserBattleInfo> excludeList){
        ShuiHuYeZiCardActivityConfig config = ShuiHuYeZiCardActivityConfigMgr.getActivityConfig(item.getActivityId());

        int level = ShuiHuYeZiCardCommonMgr.getLevel(config,item.getRankScore());
        // 允许匹配的玩家集合
        List<ShuiHuYeZiCardUserBattleInfo> targetList = new ArrayList<>();
        for (ShuiHuYeZiCardUserBattleInfo target : waitingPlayerMap.values()){
            if(target.getUserId() == item.getUserId()){
                continue;
            }
            if(isFilterSameServer && target.getServerId() == item.getServerId()){
                // 过滤同区服
                continue;
            }
            if(isFilterDiffModel && target.getRoomType() != item.getRoomType()){
                // 过率不同模式
                continue;
            }
            int targetLevel = ShuiHuYeZiCardCommonMgr.getLevel(config,target.getRankScore());
            if(Math.abs(level - targetLevel) > diffLevel){
                continue;
            }
            if(excludeList.contains(target)){
                continue;
            }
            targetList.add(target);
        }
        if(targetList.size() > 0){
            return targetList.get(random.nextInt(targetList.size()));
        }
        return null;
    }

    /**
     * 取消匹配
     */
    public static void overTimeMatch(ShuiHuYeZiCardUserBattleInfo item){
        ShuiHuYeZiCardProto.ShuiHuYeZiCardMatchOverTimeCrossToGameMsg.Builder crossToGameMsg = ShuiHuYeZiCardProto.ShuiHuYeZiCardMatchOverTimeCrossToGameMsg.newBuilder();
        crossToGameMsg.setRoomId(item.getRoomType());
        MessageHelper.sendPacket(item.getServerId(), item.getUserId() , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_PVP_MATCH_OVER_TIME_FROM_CROSS, crossToGameMsg));
    }

    /**
     * 加载玩家正在开启的pvp游戏
     * @param userId
     * @return
     */
    public static void loadGame(long userId ,long serverId){
        ShuiHuYeZiCardProto.ShuiHuYeZiCardLoadRoomRespMsg.Builder builder = ShuiHuYeZiCardProto.ShuiHuYeZiCardLoadRoomRespMsg.newBuilder();
        ShuiHuYeZiCardPVPRoom pvpRoom = ShuiHuYeZiCardActivityBattleMgr.pvpRoomMap.get(userId);
        if(pvpRoom == null){
            builder.setRet(GameErrorCode.E_SHUIHUYEZICARD_ACTIVITY_NOT_OPEN_GAME);
            MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(ClientProtocol.U_SHUIHUYEZICARD_LOAD_PVP_ROOM,builder));
            return;
        }
        // 下发正在开启的房间
        pvpRoom.loadGame(userId,serverId);
    }

    /**
     * 创建房间 并同步房间信息给房间玩家
     */
    public static boolean createRoom(ShuiHuYeZiCardUserBattleInfo player1,ShuiHuYeZiCardUserBattleInfo player2){
        ShuiHuYeZiCardRoomData shuiHuYeZiCardRoomData = new ShuiHuYeZiCardRoomData();
        shuiHuYeZiCardRoomData.setActivityId(player1.getActivityId());
        shuiHuYeZiCardRoomData.setRound(1);

        ShuiHuYeZiCardPVPRoom shuiHuYeZiCardPVPRoom = new ShuiHuYeZiCardPVPRoom(shuiHuYeZiCardRoomData,player1,player2);
        boolean success = shuiHuYeZiCardPVPRoom.startGame();
        if(success){
            pvpRoomMap.put(player1.getUserId(),shuiHuYeZiCardPVPRoom);
            pvpRoomMap.put(player2.getUserId(),shuiHuYeZiCardPVPRoom);
            pvpRoomList.add(shuiHuYeZiCardPVPRoom);
        }
        return success;
    }

    /**
     * 添加成功匹配的匹配时间
     * @param waitTime
     */
    private static void addWaitTime(long waitTime,List<ShuiHuYeZiCardUserBattleInfo> list){
        synchronized (recentWaitTimeList){
            if(recentWaitTimeList.size() >= 50){
                int time = recentWaitTimeList.removeFirst();
                totalWaitTime -= time;
            }
            totalWaitTime += waitTime;
            recentWaitTimeList.add((int)waitTime);
        }
        synchronized (recentJoinerList){
            Iterator<ShuiYeZiCardJoinPvpUserInfo> iterator = recentJoinerList.iterator();
            while (iterator.hasNext()){
                // 去重
                ShuiYeZiCardJoinPvpUserInfo joinPvpUserInfo = iterator.next();
                for (ShuiHuYeZiCardUserBattleInfo item : list){
                    if(joinPvpUserInfo.getUserId() == item.getUserId()){
                        iterator.remove();
                        break;
                    }
                }
            }
            for (ShuiHuYeZiCardUserBattleInfo item : list){
                recentJoinerList.add(new ShuiYeZiCardJoinPvpUserInfo(item.getUserId(),item.getActivityId(),item.getRankScore()));
            }
        }
    }

    /**
     * 向区服同步玩家信息
     * @param userId
     * @param serverId
     * @param roomId
     */
    public static void synUserDataToGameServer(long userId,long serverId,int roomId){
        ShuiHuYeZiCardProto.ShuiHuYeZiCardPvpSynUserDataCrossToGameMsg.Builder builder = ShuiHuYeZiCardProto.ShuiHuYeZiCardPvpSynUserDataCrossToGameMsg.newBuilder();
        builder.setRoomId(roomId);
        MessageHelper.sendPacket(serverId, userId , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_PVP_SYN_USER_DATA_FROM_CROSS, builder));
    }

    /**
     * 离线
     * @param userId
     */
    public static void offline(long userId){
        // 取消匹配
        ShuiHuYeZiCardUserBattleInfo battleInfo = waitingPlayerMap.remove(userId);
        if(battleInfo != null){
            // 成功取消
            ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchGameToServerMsg.Builder crossMsg = ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchGameToServerMsg.newBuilder();
            ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchRespMsg.Builder stcMsg = ShuiHuYeZiCardProto.ShuiHuYeZiCardCancelMatchRespMsg.newBuilder();
            stcMsg.setRet(0);
            crossMsg.setRoomType(battleInfo.getRoomType());
            crossMsg.setStcMsg(stcMsg);
            MessageHelper.sendPacket(battleInfo.getServerId(), userId , YanQuMessageUtils.buildMessage(GameProtocol.S_SHUIHUYEZICARD_CANCEL_MATCH_FROM_CROSS, crossMsg));
        }
    }


    @Override
    public boolean init() throws Exception {
        return true;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        logger.info("水浒叶子牌停服时，当前正在开启的房间数为：{},正在匹配的人数为：{}",pvpRoomList.size(),waitingPlayerMap.size());
        for (ShuiHuYeZiCardPVPRoom item : pvpRoomList){
            logger.info("水浒叶子牌停服时，正在对战的玩家1：{}，玩家2：{}",item.getPlayer1().getUserId(),item.getPlayer2().getUserId());
        }
        return true;
    }
}
